﻿<%@ page language="java" pageEncoding="UTF-8" isELIgnored="false"%>
<%@page import="global.Constants"%>
<%@page import="util.ServletHelp"%>
<%@page import="com.aiflow.Action.DictionaryAction;"%>
<html>
<head>
<%
String heraldIds = request.getParameter("heraldIds");
%>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script type="text/javascript">
	var alarmTypes = [];
	var editHeraldFormPanel = null;
	var sexStore ;
			          var checkid ='-1' ;
  	                  var  checktext = '' ;

		$(document).ready(function(){
		
		 				 
		
		        
			// 工具栏
		    var toolbar = new Ext.Toolbar({
		    	renderTo: 'editHeraldToolBarDiv',
		    	items: [
				    new Ext.Button({
					    id: 'editHerald-save-button',
						text: '保存',
						iconCls: 'tick'
					}),
					new Ext.Button({
					    id: 'editHerald-cancel-button',
						text: '取消',
						iconCls: 'cancel'
					})
				]
			});
               
// 告警类型数据源
	        var alarmStore = new Ext.data.ArrayStore({  
	            fields : ['alarm_id', 'alarm_name'],  
	            data : <%=DictionaryAction.getDictionaryCombo("79")%>,
	            sortInfo: {field: "alarm_id", direction: "ASC"}
	        });
	        
	        
	        
		   //  告警对象 树      
		   var comboWithTooltipHerald = new Ext.form.ComboBox({
		    id:'ch',
		    fieldLabel: '传报对象',
            store:new Ext.data.SimpleStore({fields:[],data:[[]]}),  
            editable:false,  
             hiddenName:'target_name',
           //  hiddenId:'dicId',
             hiddenId:'alarmTargetId',
            mode: 'local',  
            triggerAction:'all',  
            maxHeight: 200, 
			allowBlank:false, 
            tpl: '<div style="height:200px"><div id="treeHerald"></div></div>',  
            onSelect:Ext.emptyFn,
            emptyText:'请选择...',
            anchor:'98%',
            applyTo: 'comboxtreeHerald'  
        });
       
        comboWithTooltipHerald.render('comboWithTooltipHerald');  
        
        var treeHerald = new Ext.tree.TreePanel({  
                border:false,  
                autoScroll:true,
                animate:true,
                autoWidth:true,
                autoHeight:true,
                enableDD:true,
                containerScroll: true, 
                loader: new Ext.tree.TreeLoader({
                    dataUrl:'${pageContext.request.contextPath}/dictionary_getDictionaryTree.action?alarmId='+<%=heraldIds%>,
                    listeners : {
					beforeload : function(treeLoader, node) {
						this.baseParams.parentId = node.id
						this.baseParams.text = node.text
						this.baseParams.leaf = node.leaf
					}
				}           
                })
            });
            
        var rootHerald = new Ext.tree.AsyncTreeNode({
                id:'76',                      //节点id
                text: '传报对象',                  //节点名称
                draggable:true,                  //是否支持拖动
                nodeType: 'async', 
                leaf:false,
                checked : false
        });
          
            treeHerald.setRootNode(rootHerald);
            
           
            comboWithTooltipHerald.on('expand',function(){  
            treeHerald.render('treeHerald');  
            //加载所有的子节点
            //tree.expandAll(); 
               // rootHerald.eachChild(
                     
               
            
            
            });  
            
        
        treeHerald.on('checkchange', function(node, checked) {
                        node.expand();
                        node.attributes.checked = checked;
                        node.eachChild(function(child) {
                                    child.ui.toggleCheck(checked);
                                    child.attributes.checked = checked;
                                    child.fireEvent('checkchange', child,
                                            checked);
                               });
                            //这里是遍历勾选的角色
                            var b = treeHerald.getChecked();
                            checkid = new Array;// 存放选中id的数组
                            checktext = new Array;// 存放选中text的数组
                            for (var i = 0; i < b.length; i++) {
                                checktext.push(b[i].text);// 添加text到数组
                                checkid.push(b[i].id);// 添加id到数组
                                
                            }
                       comboWithTooltipHerald.setValue(checktext.toString());
                    }, treeHerald);
            
          
       //  告警对象 树     结束 
	        

		 	// 编辑用户Form
			var editHeraldFormPanel = new Ext.FormPanel({
				renderTo: 'editHeraldFormDiv',
		        labelWidth: 60,
		        border: false,
		        bodyStyle: 'background-color:transparent;',
		  //          url: '${pageContext.request.contextPath}/dictionary_updateHeral.action?checkid='+checkid.toString()+"&checktext"+checktext.toString(),
		          items: [{
		            layout:'form',
		            border: false,
		            bodyStyle: 'padding:5px;background-color:transparent;',
		            items:[{//  传报编号
			                xtype:'hidden',
			                id: 'id',
			                name: 'id',
			                fieldLabel: '传报编号',
			                readOnly: true,
			                anchor:'98%',
			                allowBlank:false,
			                
			                maxLength: 20
		                   },{//  传报编号
			                xtype:'hidden',
			                id: 'targetName',
			                name: 'targetName',
			                fieldLabel: '传报对象',
			                readOnly: true,
			                anchor:'98%',
			                allowBlank:false,
			                width: 230,
			                maxLength: 20
		                   },
		                   {  
			                xtype:'combo',
			                hiddenName: 'alarm_id',
			      
			                fieldLabel: '告警类型',
			                store: alarmStore,
			                mode : 'local',
			                triggerAction: "all",
			                valueField: 'alarm_id',
			                displayField: 'alarm_name',
			                allowBlank:false,
			                editable: false,
							allowBlank:false,
			                width: 230,
			                anchor:'98%'
			           },comboWithTooltipHerald,   // 传报对象
		                { 
		xtype:'timefield',  
		columnWidth:.5 ,            
                maxValue:'23:30',                      //最大时间   
                maxText:'所选时间小于{0}',  
                minValue:'00:00',                      //最小时间   
                minText:'所选时间大于{0}',  
                maxHeight:70,  
                increment:30,   
				allowBlank:false,
                name: 'staTime', 
                id: 'heraldstaTime',  
		anchor:'68%' ,                   //时间间隔   
                format:'G:i:s',                    //时间格式   
                invalidText:'时间格式无效',  
                fieldLabel:'开始时间'  
				},{ 
						xtype:'timefield',  
		columnWidth:.5 ,            
                maxValue:'23:30',                      //最大时间   
                maxText:'所选时间小于{0}',  
                minValue:'00:00',                      //最小时间   
                minText:'所选时间大于{0}',  
                maxHeight:70,  
                increment:30,   
				allowBlank:false,
                name: 'endTime', 
                id: 'heraldendTime',  
		anchor:'68%' ,                   //时间间隔   
                format:'G:i:s',                    //时间格式   
                invalidText:'时间格式无效',  
                fieldLabel:'结束时间'
},{//   格式
			                xtype:'textarea',
			                name: 'pattern',
			                id:'pattern',
			                fieldLabel:'传报格式',
			                width: 230,
							allowBlank:false,
			                anchor:'98%'
			              
		                },{// 操作类型
				           id:'buttonType',
			               xtype:'hidden',
			               name: 'type',
			               value: 'cancel'
			           }]
		        }]
		    });


		    // 发送请求-form初期化
		  
			Anynote.ajaxRequest({
				baseParams: {heraldId:<%=heraldIds%>},
				action: '${pageContext.request.contextPath}/herald_getHeral.action',
				callback: function(jsonResult){
				          //alert(editHeraldFormPanel);
		     	           editHeraldFormPanel.getForm().setValues(jsonResult);
		     	  
		     	       
		     	           //Ext.get("nameq").setValue(2); 

 
				}
			});

		    // 保存按钮
		    $("#editHerald-save-button").click(function(){

			    var form = editHeraldFormPanel.getForm();
			    form.findField("targetName").setValue(checktext.toString()) ; 
			      
			    if(form.isValid()){
			    	// 发送请求
					Anynote.ajaxRequest({
					 
						baseParams: form.getValues(),
						 
						action: '${pageContext.request.contextPath}/herald_updateHeral.action?checkid='+checkid.toString(),
						callback: function(jsonResult){
						    // location.href="${pageContext.request.contextPath}/page/index.jsp";
						     heraldListGrid.getStore().reload();
						    	editHeraldWindow.close();
						},
						showWaiting: true,
						failureMsg: '保存失败.'
					});
				}
			});
			
		 	// 取消按钮
		    $("#editHerald-cancel-button").click(function(){
		    	Ext.getCmp("buttonType").setValue("cancel");
		    	editHeraldWindow.close();
			});
		});
	</script>
</head>
<body> 
<div id="editHeraldDiv" style="width:100%;height:100%;">
	<div id="editHeraldToolBarDiv"></div>
	<div id="editHeraldFormDiv""></div>
</div>

<div id="textDiv" style="display:none">
<input type="text" name="comboxtreeHerald" id="comboxtreeHerald">
</div>
</body>
</html>